/*************************************************************************
    > File Name: face_track_task.cpp
    > Author: fanzhihui
    > Mail: 953106194@qq.com 
    > Created Time: 2019年06月28日 星期五 11时03分19秒
 ************************************************************************/
#include "face_track_task.h"
#include "httplib.h"
#include "json/json.h"
#include "config.h"
#include "resposity.h"
#include<iostream>
#include "opencv/cv.h"
#include "image_base64.h"
#include "baidu_face_api.h"

using namespace std;
using namespace httplib;
using namespace cv;

void FaceTrackTask::Execute(TaskThread* thread_context,void *app_context)
{
	time_t timestamp = time(NULL);
	Json::Value valueinfo;
	valueinfo["srcImg"] = src_img;
	valueinfo["machineId"] = Config::machine_id;
	valueinfo["timestamp"] = uint32_t(timestamp);


	for( uint32_t i = 0; i < tracked_faces.size(); i++ ) {

		Json::Value array;	
		array["x"] = tracked_faces[i].center_x;  
		array["y"] = tracked_faces[i].center_y;
		array["width"] = tracked_faces[i].width;
		valueinfo["faces"].append(array);
	}
	Json::FastWriter writerinfo;
	string value = writerinfo.write(valueinfo);

	//发布
	string channel = "tracks";
	int ret = Resposity::getInstance()->getRedis()->Publish(channel,value);
	std::cout << "channel:" << channel << " ret:" << ret << std::endl;
}


